package day02;

import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

public class Train {
	

	//main
	public static void main(String[] args) {
		System.out.println("HelloWorld");
		int age = 23;
		age =24;
		String name = "张三";
		System.out.println(name + "的年龄是" + age);
		
	}

	@Test
	public void test01() {
		// 在编码表里面a使用97表示
		char ch = 'a';
		System.out.println(ch);//a
		System.out.println(ch + 1);//98
		System.out.println((char) (ch + 1));//b
		System.out.println((char) (ch + 2));//c
		System.out.println((int) 3.14);//3
	}
	
	@Test
	public void test02() {
		int num1 = 3;
		int num2 = 5;
		int result = num1 + num2;
		System.out.println(result);
		System.out.println(8 / 2);
		System.out.println(8 % 3);
		System.out.println(8 / 3);
	}
	
	@Test
	public void test03() {
		int i = 3;
		i++;
		System.out.println(i);//4
		// 这里是被println这个方法使用，i++先使用后++
		System.out.println(i++);//4(i = 5)
		// ++放在前面是先++，后使用
		System.out.println(++i);//6
		
	}
	
	@Test
	public void test04() {
		System.out.println((char)65);
	}
	
	@Test
	public void test05() {
		int i = 1;
		while(i <= 5) {
			System.out.println("HelloWorld");
			i++;
		}
	}
	
	@Test
	public void test06() {
		int i = 1;
		int sum = 0;
		while(i <=100) {
			System.out.println(i);
			sum = sum + i;
			i++;
		}
		System.out.println("sum:" + sum);
	}
	
	@Test
	public void test07() {
		for(int i = 1; i <= 5; i++) {
			System.out.println("HelloWorld");
		}
	}
	
	@Test
	public void test08() {
		int sum = 0;
		for(int i =1; i <= 100; i++) {
			System.out.println(i);
			sum = sum + i;
		}
		System.out.println("sum:" + sum);
		
	}
	
	@Test
	public void test09() {
		Scanner scanner = new Scanner(System.in);
		// Random().nextInt(300)   		0~299
		// Random().nextInt(300)+1      1~300
		int random = new Random().nextInt(300) + 1;
		System.out.println(random);
		// for (;;) {}
		while (true) {
			System.out.println("猜吧！");
			int num = scanner.nextInt();
			if (num > random) {
				System.out.println("太大了");
			} else if (num < random) {
				System.out.println("太小了");
			} else {
				System.out.println("猜对了");
				// 退出while循环
		break;
			}
		}
	}
	
	@Test
	public void test10() {
		Scanner scanner = new Scanner(System.in);
		int password = 0;
		do {
			System.out.println("请输入密码：");
			password = scanner.nextInt();
		}while (password != 123);
	}
	
	@Test
	public void test11() {
		int count = 0;
		for (int i = 1; i <= 100; i++) {
			if (i % 7 == 0) {
				
			System.out.println(i);
			count++;
			System.out.println("count:" + count);
			
		    }
	    }
		System.out.println("count: " + count);
    }
	
	@Test
	public void test12() {
		for (int i = 1; i <= 9; i++) {
			
			System.out.println(i + "*9" + "=" + (i * 9) + "\t");
			
		}
	}
	@Test
	public void test13() {
		for (int i = 1; i <= 4; i++) {
			System.out.println("*");
		}
		System.out.println("--------");
	}
	@Test
	public void test14() {
		for (int i = 1; i <= 3; i++) {// i=1,代表打印第一行
			for (int j = 1; j <= 4; j++) {
				System.out.print("*");
			}
			System.out.println();// 打印完一行之后换行
		}
	}
	
	@Test
	public void test15() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}
	
	@Test
	public void test16() {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j + "*" + i + "=" + (i * j) + "\t");
				
			}
			System.out.println();
		}
	}

	@Test
	public void test17() {
		//int num = 3;
				byte num = 3;
				switch (num) {
				case 1:
					System.out.println("1");
				break;
				case 2:
					System.out.println("2");
				break;
				case 3:
					System.out.println("3");
				break;
				default:
					System.out.println("default");
				break;
				}
	}
	
	@Test
	public void test18() {
		String str = "a";
		switch (str) {
		case "a":
			System.out.println("a");
		break;
		case "b":
			System.out.println("b");
		break;
		default:
		break;
		}
	}
	
//	输入月份、年份判断天数：
//	1、3、5、7、8、10、12  -------- 31天
//	4、6 、9、11--------------------30天
//	2----------------------------------28/29天
	@Test
	public void test19() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入月份：");
		int month = scanner.nextInt();//读入读者的输入
		switch (month) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 10:
		case 8:
		case 12:
			System.out.println("31天");
		break;
		case 4:
		case 6:
			System.out.println("30天");
			break;
		case 2:
			System.out.println("请输入年份：");
			int year = scanner.nextInt();
			if (year % 4 == 0) {
				System.out.println("28天");
				
			}else {
				System.out.println("29天");
				
			}
		break;
		default:
		break;
		}
		
		
		
		
	}
	
	@Test
	public void test20() {
		int score = 100;
		switch (score / 10) {
		case 10:
		case 9:
			System.out.println("优秀");
			break;
		case 8:
			System.out.println("良好");
			break;
		case 7:
			System.out.println("一般");
			break;
		case 6:
			System.out.println("及格");
			break;
		case 5:
		case 4:
		case 3:
		case 2:
		case 1:
		case 0:
			System.out.println("不及格");
		break;
		default:
			System.out.println("default");
		break;
		}
    }
	
	@Test
	public void test21() {
		for (int i = 1; i <= 5; i++) {
			if(i == 3) {
				continue;
			}
			System.out.println(i);
		}
		
	}
	@Test
	public void test22() {
		for (int i = 1; i <= 5; i++) {
			if(i == 3) {
				break;
			}
			System.out.println(i);
			
		}
	}
	
	@Test
	public void test23() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= 5; j++) {
				if (j == 3 ) {
					break;
				}
				System.out.println(j);
			}
		}
	}
}
